package com.gmtx.syb;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.gmtx.syb.application.MyApplication;
import com.gmtx.syb.dialog.RequestLoginDialog;
import com.gmtx.syb.home.view.HomeFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.iv_icon_home_foot)
    ImageView iv_icon_home_foot;
    @BindView(R.id.iv_icon_sort_foot)
    ImageView iv_icon_sort_foot;
    @BindView(R.id.iv_icon_like_foot)
    ImageView iv_icon_like_foot;
    @BindView(R.id.iv_icon_shop_foot)
    ImageView iv_icon_shop_foot;
    @BindView(R.id.iv_icon_mine_foot)
    ImageView iv_icon_mine_foot;

    @BindView(R.id.tv_icon_home_foot)
    TextView tv_icon_home_foot;
    @BindView(R.id.tv_icon_sort_foot)
    TextView tv_icon_sort_foot;
    @BindView(R.id.tv_icon_like_foot)
    TextView tv_icon_like_foot;
    @BindView(R.id.tv_icon_shop_foot)
    TextView tv_icon_shop_foot;
    @BindView(R.id.tv_icon_mine_foot)
    TextView tv_icon_mine_foot;

    public static final String TAG = "MainActivity";
    private HomeFragment homeFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setViews();
        init();
    }

    private void init() {
        setSysSize();
    }

    private void setViews() {

    }

    @OnClick({R.id.container_home_foot,R.id.container_sort_foot,R.id.container_like_foot,R.id.container_shop_foot,R.id.container_mine_foot})
    public void onClick(View view){
        switch (view.getId()) {
            case R.id.container_home_foot:
                resetFootIcon();
                iv_icon_home_foot.setImageResource(R.mipmap.sy3x_icon);
                tv_icon_home_foot.setTextColor(getResources().getColor(R.color.zhx_color));
                homeFragment = new HomeFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.container_frame_main, homeFragment).commit();
                break;
            case R.id.container_sort_foot:
                resetFootIcon();
                iv_icon_sort_foot.setImageResource(R.mipmap.fl3x_icon);
                tv_icon_sort_foot.setTextColor(getResources().getColor(R.color.zhx_color));
                break;
            case R.id.container_like_foot:
                resetFootIcon();
                iv_icon_like_foot.setImageResource(R.mipmap.gz3x_icon);
                tv_icon_like_foot.setTextColor(getResources().getColor(R.color.zhx_color));
                break;
            case R.id.container_shop_foot:
                resetFootIcon();
                iv_icon_shop_foot.setImageResource(R.mipmap.gwc3x_icon);
                tv_icon_shop_foot.setTextColor(getResources().getColor(R.color.zhx_color));
                //RequestLoginDialog.getRequestLoginDialog(this).hide();
                break;
            case R.id.container_mine_foot:
                resetFootIcon();
                iv_icon_mine_foot.setImageResource(R.mipmap.wode3x_icon);
                tv_icon_mine_foot.setTextColor(getResources().getColor(R.color.zhx_color));
                //RequestLoginDialog.getRequestLoginDialog(this).show();

                break;
        }
    }

    private void resetFootIcon(){
        iv_icon_home_foot.setImageResource(R.mipmap.shouye3x_icon);
        iv_icon_sort_foot.setImageResource(R.mipmap.fenlei3xi_icon);
        iv_icon_like_foot.setImageResource(R.mipmap.guanzhu3x_icon);
        iv_icon_shop_foot.setImageResource(R.mipmap.gouwuche3x_icon);
        iv_icon_mine_foot.setImageResource(R.mipmap.wd3x_icon);
        tv_icon_home_foot.setTextColor(getResources().getColor(R.color.dark_grey));
        tv_icon_sort_foot.setTextColor(getResources().getColor(R.color.dark_grey));
        tv_icon_like_foot.setTextColor(getResources().getColor(R.color.dark_grey));
        tv_icon_shop_foot.setTextColor(getResources().getColor(R.color.dark_grey));
        tv_icon_mine_foot.setTextColor(getResources().getColor(R.color.dark_grey));
    }

    //获取系统屏幕的宽高
    private void setSysSize(){

        if (MyApplication.window_height <= 1 || MyApplication.window_width <= 1) {

            DisplayMetrics dm = new DisplayMetrics();
            //获取屏幕信息
            getWindowManager().getDefaultDisplay().getMetrics(dm);
            int screenWidth = dm.widthPixels;
            int screenHeight = dm.heightPixels;

            MyApplication.window_height = screenHeight;
            MyApplication.window_width = screenWidth;

            Log.d(TAG, MyApplication.window_height+ "" + " 高");
            Log.d(TAG, MyApplication.window_width + "" + "  宽");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
